package StudyCode.summary.myfile;

import java.io.IOException;
import java.nio.file.FileStore;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class GetFileSystemAttribute {
	public static void main(String[] args) {
		Path path = Paths.get("E:/Copy/test.txt");
		try {
			FileStore store = Files.getFileStore(path);

			long total_space = store.getTotalSpace() / 1024;
			long used_space = (store.getTotalSpace() - store.getUnallocatedSpace()) / 1024;
			long available_space = store.getUsableSpace() / 1024;
			boolean is_read_only = store.isReadOnly();

			System.out.println("--- " + store.name() + " --- " + store.type());
			System.out.println("总空间: " + total_space);
			System.out.println("已用空间: " + used_space);
			System.out.println("可用空间: " + available_space);
			System.out.println("是否只读? " + is_read_only);
		} catch (IOException e) {
			System.err.println(e);
		}
	}
}
